#!/usr/bin/python

#*************************************************************************
# 
# Copyright 2008 by Sun Microsystems, Inc.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# This file is part of OpenOffice.org/ootermite.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# only, as published by the Free Software Foundation.
#
# OpenOffice.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License version 3 for more details
# (a copy is included in the LICENSE file that accompanied this code).
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with OpenOffice.org.  If not, see
# <http://www.openoffice.org/license.html>
# for a copy of the LGPLv3 License.
#
#*************************************************************************

import getopt
import os
import os.path
import sys

def main():
    # Parse all posible commands
    opts, args = getopt.getopt(sys.argv[1:], "hbnNsrliw", ["help", "branch=", "buildername=", "buildnumber=", "slavename=", "revision=", "languages=", "install_set=", "workdir="])

    makeInstallSet = False
    installSetFile = "install_set.zip"

    for opt, arg in opts:
        if opt in ("-i", "--install_set"):
            if arg == "on" or arg == "true":
                makeInstallSet = True
                
    if not makeInstallSet:
        sys.exit(65) # Skipping install set
    
    # Delete old install_set.zip
    try:
        os.remove(installSetFile)
    except:
        print "File %s does not exist, so we cannot delete it." % installSetFile
    
    # Bundle the install_set, preferably as bz2, but due to compatibility issues
    # we still use ZIP
    dircmd  = "cd instsetoo_native/*.pro"
    zipcmd  = "zip -9 ../../%s -@" % installSetFile
    findcmd = "_nofile_"
    
    # MacOS
    if os.path.exists("MacOSXX86Env.Set.sh"):
        findcmd = "find . -name \*.dmg -print"
        dircmd  = "cd instsetoo_native/unxmacxi.pro"
           
    # Debian/GNU Linux AMD64
    elif os.path.exists("LinuxX86-64Env.Set.sh"):
        findcmd = "find . -name \*.deb -print"
        dircmd  = "cd instsetoo_native/unxlngx6.pro"
                
    # Debian/GNU Linux x86
    elif os.path.exists("LinuxX86Env.Set.sh"):
        findcmd = "find . -name \*.deb -print"
        dircmd  = "cd instsetoo_native/unxlngi6.pro"
        
    # Solaris 10 Intel (unxsoli4.pro)
    elif os.path.exists("SolarisX86Env.Set.sh"):
        proc = os.system("../../bundle.soli")
        sys.exit(proc)
        
    # Solaris 10 SPARC
    elif os.path.exists("SolarisSparcEnv.Set.sh"):
        proc = os.system("../../bundle.sols")
        sys.exit(proc)
    
    # Windows
    elif os.path.exists("winenv.set.sh"):
        proc = os.system("../../bundle.win")
        sys.exit(proc)
        
    else:
        print "Bundling for this platform is currently not supported!"
        sys.exit(65)
        
    # Execute the command
    proc = os.system("%s ; %s | %s" % (dircmd, findcmd, zipcmd))
    sys.exit(proc)
    
# Call entrypoint method
main()

